home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10145 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: iafrica.com!usenet
  2. From: Peter Golda <goldap@telkom11.telkom.co.za>
  3. Newsgroups: comp.lang.c++
  4. Subject: Default values for constructor arguments
  5. Date: 6 Mar 1996 10:17:51 GMT
  6. Organization: Telkom
  7. Message-ID: <4hjoof$5qk@newnews.iafrica.com>
  8. NNTP-Posting-Host: wfor-koeppenp.telkom.co.za
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  13.  
  14. Hi,
  15.  
  16. I had a constructor for my MWMessageLog class as follows:
  17.  
  18.     MWMessageLog(
  19.         const RWCString& anExecutableCode,
  20.         const RWCString& aSystemCode,
  21.         const RWCString& aLogFilePath );
  22.  
  23. where the class RWCString comes from the Rogue Wave development library
  24. and is just a simple string class.
  25.  
  26. Now, I wanted to add default values, so I wrote as follows (knowing that
  27. RWCString has a constructor that constructs RWCString from char* and it
  28. has an assignment operator):
  29.  
  30.    MWMessageLog(
  31.        ...
  32.        ...
  33.        const RWCString& aLogFilePath = "~/logs/" );
  34.  
  35. but now the compiler moans that it doesn't like that since the default
  36. value must be passed through a constructor. 
  37.  
  38. So, I thought I'd create a static member variable in my class of
  39. type RWCstring; initialise it to "~/logs/" and then use the variable's
  40. name as my default value in the constructor. But that fails too.
  41.  
  42. The C++ ARM has an example of something similar on page 143 (Ch8, Default 
  43. Arguments) - but it doesn't seem to work...
  44.  
  45. My question thus is:
  46.  
  47. Can I use default values with classes/types that are not inbuilt, but
  48. may be constructed of one inbuilt type value. If so, how can I do it
  49. without making a big mess of things ?
  50.  
  51. Thanks,
  52. Pete.
  53.  
  54.  
  55.